package com.bookstore.bauhinia.book.service.impl;

import com.bookstore.bauhinia.book.service.BookService;
import com.bookstore.bauhinia.mapper.BookMapper;
import com.bookstore.bauhinia.pojo.Book;
import com.bookstore.bauhinia.pojo.BookExample;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class BookServiceImpl implements BookService {
    @Resource
    private BookMapper bookMapper;

    @Override
    public Book selectByPrimaryKey(Integer id) {
        return bookMapper.selectByPrimaryKey(id);
    }

    @Override
    public int insert(Book record) {
        return bookMapper.insertSelective(record);
    }

    @Override
    public int deleteByPrimaryKey(Integer id) {
        return bookMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int updateByPrimaryKey(Book record) {
        return bookMapper.updateByPrimaryKey(record);
    }

    @Override
    public List<Book> getAllBooks() {
        return bookMapper.selectByExample(new BookExample());
    }

    @Override
    public List<Book> getBooksByCategoryId(Integer categoryId) {
        BookExample example = new BookExample();
        BookExample.Criteria criteria = example.createCriteria();
        criteria.andCategoryIdEqualTo(categoryId);
        return bookMapper.selectByExample(example);
    }
}